// SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
// SPDX-License-Identifier: Mulan PSL v2
package com.geniusai.aip.auth.utils;

import java.math.BigDecimal;

/**
 * @author hml14563
 * @date 2021/5/15
 */
public class DecimalUtils {
    /**
     * 保留小数后3位
     */
    public static double get3DotNum(Double num) {
        String result = String.format("%.3f", num);
        return Double.parseDouble(result);
    }

    public static Integer bytes2Gb(Long from) {
        if (from < 0) {
            return -1;
        } else {
            return (int) (from / 1024 / 1024 / 1024);
        }
    }

    public static double mb2Gb(Integer from) {
        if (from < 0) {
            return -1d;
        } else {
            return BigDecimal.valueOf(from).divide(BigDecimal.valueOf(1024))
                    .setScale(3, BigDecimal.ROUND_CEILING).doubleValue();
        }
    }
}
